import QtQuick 2.7
import QtQuick.Controls 2.3
import QtQuick.Layouts 1.3

Dialog{
    id: dialog
    implicitWidth:400
    implicitHeight: 220
    x:(parentItem.width-width)/2
    y:(parentItem.height-height)/2


    property var btnType:DialogButtonBox.Ignore
    property Item parentItem


    property alias label:describe.text
    property alias type: control.state


    parent: parentItem

    modal:true
    dim:true
    closePolicy:Popup.CloseOnEscape


    Container{
        id:control
        anchors.fill: parent
        contentItem: ColumnLayout{
            spacing: 2
            Repeater{
                model: control.contentModel
            }
        }
        Image{
            id:_pic
            Layout.alignment: Qt.AlignCenter
        }

        Text {
            id: describe
            Layout.alignment: Qt.AlignCenter
            font.pixelSize: 20
            color: "red"
            font.family: "Microsoft Yahei"
        }

        states: [
            State {
                name: "Info"
                PropertyChanges {
                    target: _pic
                    source:"content/info.png"
                }
                PropertyChanges {
                    target: dialog
                    btnType:DialogButtonBox.Ok| DialogButtonBox.Cancel
                }
            },
            State {
                name: "Warn"
                PropertyChanges {
                    target: _pic
                    source:"content/warning.png"
                }
                PropertyChanges {
                    target: dialog
                    btnType:DialogButtonBox.Ignore | DialogButtonBox.Cancel
                }
            },
            State {
                name: "Error"
                PropertyChanges {
                    target: _pic
                    source:"content/error.png"
                }
                PropertyChanges {
                    target: dialog
                    btnType: DialogButtonBox.Ignore| DialogButtonBox.Retry| DialogButtonBox.Abort
                }
            }
        ]

    }


    footer:DialogButtonBox {
             standardButtons: btnType
//             onAccepted: console.log("Ok clicked")
//             onRejected: console.log("Cancel clicked")
//             delegate:
//             Button{
//                text:  judgedType(btnType,DialogButtonBox.standardButton)
//             }

//             MButton{
//                 //name:DialogButtonBox.name
//                 DialogButtonBox.buttonRole: DialogButtonBox.standardButtons
//             }
        }


}
